#ifndef SIMPLEAMQPCLIENT_BASICMESSAGE_H
#define SIMPLEAMQPCLIENT_BASICMESSAGE_H
/*
 * ***** BEGIN LICENSE BLOCK *****
 * Version: MIT
 *
 * Copyright (c) 2010-2013 Alan Antonuk
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 * ***** END LICENSE BLOCK *****
 */


#include <string>
#include "Util.h"
#include "Property.h"

namespace amqp {

    namespace Detail {
        class MessageImpl;
    }

    class Message;
    typedef std::shared_ptr<Message> MessagePtr;

    class  Message : noncopyable {
      public:
        /**
         * Create a new empty Message object
         */
        static MessagePtr Create() { return std::make_shared<Message>(); }

        /**
         * Create a new Message object
         * Creates a new Message object with a given body
         * @param body the message body.
         * @returns a new Message object
         */
        static MessagePtr Create(const std::string &body) {
            return std::make_shared<Message>(body);
        }

        /**
         * Create a new Message object
         * Creates a new Message object with a given body, properties
         * @param body the message body. The message body is NOT duplicated.
         * Passed in message body is deallocated when: body is set or message is
         * destructed.
         * @properties the amqp_basic_properties_t struct. Note this makes a deep
         * copy of the properties struct
         * @returns a new Message object
         */
        static MessagePtr Create(amqp_bytes_t &body, amqp_basic_properties_t *properties) {
            return std::make_shared<Message>(body, properties);
        }

        Message();
        Message(const std::string &body);
        Message(const amqp_bytes_t&body, const amqp_basic_properties_t*properties);

      public:
        /**
         * Destructor
         */
        virtual ~Message();

        const amqp_basic_properties_t_ * getProperties() const;
        const amqp_bytes_t&getBody() const;
        amqp_bytes_t getBodyAndReset();

        std::string Body() const;
        void Body(const std::string &body);

        Property& getProp() { return m_prop; }

      protected:
        Property        m_prop;
        amqp_bytes_t    m_body;
    };

}  // namespace amqp

#ifdef _MSC_VER
#pragma warning(pop)
#endif

#endif  // SIMPLEAMQPCLIENT_BASICMESSAGE_H
